﻿<%@ Page Title="" Language="C#" MasterPageFile="~/_Default.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication.Register" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="Content/Css/Session.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="main-body">
        <div class="login-main">
            <div class="login-top">
                <span>用户注册</span>
                <span class="bg1"></span>
                <span class="bg2"></span>
            </div>
            <div class="layui-form login-bottom">
                <div class="center">
                    <div class="item">
                        <span class="icon icon-2"></span>
                        <input type="text" name="username" lay-verify="username" placeholder="请输入注册账号" maxlength="24" />
                    </div>

                    <div class="item">
                        <span class="icon icon-3"></span>
                        <input type="password" name="password" lay-verify="password" placeholder="请输入密码" maxlength="20" />
                        <span class="bind-password icon icon-4"></span>
                    </div>

                </div>
                <div class="layui-form-item" style="text-align: center; width: 100%; height: 100%; margin: 0px;">
                    <button type="button" class="login-btn" lay-submit="" lay-filter="login">立即注册</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).keyup(e => {
            if (e.keyCode == 13) {
                $('.login-btn').click()
            }
        })
        layui.use(['form', 'jquery'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;

            // 登录过期的时候，跳出ifram框架
            if (top.location != self.location) top.location = self.location;

            $('.bind-password').on('click', function () {
                if ($(this).hasClass('icon-5')) {
                    $(this).removeClass('icon-5');
                    $("input[name='password']").attr('type', 'password');
                } else {
                    $(this).addClass('icon-5');
                    $("input[name='password']").attr('type', 'text');
                }
            });

            $('.icon-nocheck').on('click', function () {
                if ($(this).hasClass('icon-check')) {
                    $(this).removeClass('icon-check');
                } else {
                    $(this).addClass('icon-check');
                }
            });

            

            // 进行登录操作
            form.on('submit(login)', function (data) {
                data = data.field;
                if (data.username == '') {
                    layer.msg('用户名不能为空');
                    return false;
                }

                if (data.username.length < 3) {
                    layer.msg('用户名不能小于3位');
                    return false;
                }

                if (data.password == '') {
                    layer.msg('密码不能为空');
                    return false;
                }

                $.ajax({
                    url: "/User/Handle.aspx",
                    method: "post",
                    data: {
                        action:"Register",
                        UserName: data.username,
                        UserPwd:data.password,
                    },
                    success: (res) => {
                        location.href = "/";
                    }
                })
                return true;
            });
        });
    </script>
</asp:Content>
